﻿using BaseData.ApplicationLib.Commands;
using BaseData.ApplicationLib.Queries;
using BaseData.CommonLib.Constants;
using BaseData.CommonLib.Models;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace BaseData.WebApi.Controllers;

[ApiController]
public class WorkingCalendarController : ControllerBase
{
    private readonly IMediator _mediator;
    private readonly IWorkingCalendarQueries _workingCalendarQueries;

    public WorkingCalendarController(IMediator mediator,
        IWorkingCalendarQueries workingCalendarQueries)
    {
        _mediator = mediator;
        _workingCalendarQueries = workingCalendarQueries;
    }

    [HttpGet(ApiRoutes.WorkingCalendar.GetWorkingCalendar)]
    public async Task<IActionResult> Get([FromQuery] WorkingCalendarSearchRequestDto model)
    {
        if (model.Page > 0 || model.Limit > 0)
        {
            var result = await _workingCalendarQueries.QueryWorkingCalendarsByPage(model);
            return Ok(result);
        }
        else
        {
            var result = await _workingCalendarQueries.QueryWorkingCalendars(model);
            return Ok(result);
        }
    }

    [HttpPost(ApiRoutes.WorkingCalendar.CreateWorkingCalendar)]
    public async Task<IActionResult> Post(CreateWorkingCalendarCommand command)
    {
        var result = await _mediator.Send(command);
        return Ok(result);
    }


}